/*
 *    Copyright © OpenAtom Foundation.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package com.inspur.edp.bef.dtgenerator.core.beActionAssembler;

import com.inspur.edp.bef.bizentity.operation.BizAction;
import com.inspur.edp.bef.dtgenerator.core.BefCoreGenCtx;
import com.inspur.edp.bef.spi.action.assembler.BEActionAssembler;
import com.inspur.edp.caf.generator.baseInfo.TypeInfo;
import com.inspur.edp.caf.generator.item.ClassGenerator;
import com.inspur.edp.caf.generator.item.ClassGeneratorContext;
import com.inspur.edp.caf.generator.method.ClassMethodGenerator;
import com.inspur.edp.cef.generator.overall.Utils;
import org.eclipse.jdt.core.dom.Modifier.ModifierKeyword;

public class CustomBEActionAssGenerator extends ClassGenerator {

  // region Static Members
  private static final String itemNameTemplate = "%1$sBEActionAssembler";
  // region BasicInfos
  private BefCoreGenCtx coreGenCtx;
  private BizAction action;

  public CustomBEActionAssGenerator(BefCoreGenCtx coreGenCtx, BizAction action) {
    super(coreGenCtx.getCompilationUnitInfo());
    this.coreGenCtx = coreGenCtx;
    this.action = action;
  }

  public static String getItemName(BizAction action) {
    return String.format(itemNameTemplate, action.getCode());
  }

  @Override
  protected String getName() {
    return getItemName(action);
  }

  @Override
  protected ClassGeneratorContext createClassInfoContext() {
    return new ClassGeneratorContext();
  }

  @Override
  protected java.util.ArrayList<ModifierKeyword> getAccessModifier() {
    return new java.util.ArrayList<ModifierKeyword>(
        java.util.Arrays.asList(ModifierKeyword.PUBLIC_KEYWORD));
  }

  @Override
  protected TypeInfo setParentClass() {
    return Utils.createTypeInfo(BEActionAssembler.class);
  }
  // endregion

  @Override
  protected java.util.ArrayList<ClassMethodGenerator> createMethodGenerators() {
    return new java.util.ArrayList<ClassMethodGenerator>(1) {};
  }

  @Override
  protected java.util.ArrayList<ClassMethodGenerator> createConstructorGenerators() {
    java.util.ArrayList<ClassMethodGenerator> result =
        new java.util.ArrayList<ClassMethodGenerator>(1);
    result.add(new CustomBEActionAssConstructorGenerator(coreGenCtx, getName(), action));
    return result;
  }

  // endregion
}
